package com.lrf.freeshipping.service;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.lrf.freeshipping.tool.Common;

public class ProductDetailService {
   
	private static String purl = "http://gw.api.alibaba.com/openapi/param2/2/portals.open/api.getPromotionProductDetail/";
	private static String appkey = "75788";
	private static String fields = "productTitle,productUrl,originalPrice,salePrice,discount,commission,validTime";
	
	//http://gw.api.alibaba.com/openapi/param2/2/portals.open/api.getPromotionProductDetail/[Appkey]? fields=[fields]&productId=[request_productId]
	
	public static  String getProductDetail(String productId) throws Exception {
		//System.out.println("url:"+purl+appkey+"?fields="+fields+"&productId="+productId);
		URL url = new URL(purl+appkey+"?fields="+fields+"&productId="+productId);		
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		if (conn.getResponseCode()==200) {
	      InputStream is = conn.getInputStream();
          return Common.streamChangeToString(is); 	
		}else {
			return null;
		}	
	}

}
